{extend name="public/baseNew" /}
{block name="body"}
<form class="form-horizontal form-contain" name="login_form" id="login_form">
    <div class="login-logo text-center"><img src="__PUBLIC__images/logo.png" alt=""></div>
    <div class="form-group">
        <label for="inputEmail3" class="col-sm-2 control-label">用户名</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="user_name" placeholder="username">
        </div>
    </div>
    <div class="form-group">
        <label for="inputPassword3" class="col-sm-2 control-label">密码</label>
        <div class="col-sm-10">
            <input type="password" class="form-control" id="password" placeholder="Password">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <div class="checkbox">
                <label>
                    <input type="checkbox" id="remember"> 记住密码
                </label>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="btn btn-primary center-block">登录</button>
        </div>
    </div>
</form>
{/block}
{block name="js"}
<script>
    $(function(){
        $("#login_form").on('submit',function(){
            login();
            return false;
            
        })
        
        
    })
function login(){
    var userName = $("#user_name").val();
    var password = $("#password").val();
    if(typeof userName == 'undefined' || userName ==''){
        alert('请输入您的用户名。');
        return false;
    }
    if(typeof password == 'undefined' || password ==''){
        alert('请输入您的密码。');
        return false;
    }
    var data = "user_name="+userName+'&password='+password;
    $.ajax({
        type: "POST",
        url: 'login',
        data: data,
        dataType:'json',
        success: function(ret){
            console.log(ret);
            if(ret.code == 200){
                location.href="/";
            }else{
                alert(ret.msg);
            }
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
            var ret = XMLHttpRequest.responseJSON
            alert(ret.msg);
        }
    })
    return false;
}




</script>
{/block}